package cn.edu.sjtu.process_status_data.async;

import cn.edu.sjtu.process_status_data.model.Status;
import cn.edu.sjtu.process_status_data.model.StatusMap;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class AsyncTask {

    @Async
    public void toReady(Integer num, Integer instance, StatusMap statusMap, long random) {
        try {
            Thread.sleep(random);
            statusMap.statusChange(num, instance, Status.ready);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Async
    public void toDone(Integer num, Integer instance, StatusMap statusMap, long random) {
        try {
            Thread.sleep(random);
            statusMap.statusChange(num, instance, Status.done);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
